/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.swt.mto.thithu.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import com.swt.mto.thithu.service.AnswerLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author tuan.nguyen
 */
public class AnswerClp extends BaseModelImpl<Answer> implements Answer {
	public AnswerClp() {
	}

	public Class<?> getModelClass() {
		return Answer.class;
	}

	public String getModelClassName() {
		return Answer.class.getName();
	}

	public long getPrimaryKey() {
		return _answerId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAnswerId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_answerId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("answerId", getAnswerId());
		attributes.put("questionId", getQuestionId());
		attributes.put("createUserId", getCreateUserId());
		attributes.put("modifyUserId", getModifyUserId());
		attributes.put("decription", getDecription());
		attributes.put("answerType", getAnswerType());
		attributes.put("correct", getCorrect());
		attributes.put("answerPosition", getAnswerPosition());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifydate", getModifydate());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long answerId = (Long)attributes.get("answerId");

		if (answerId != null) {
			setAnswerId(answerId);
		}

		Long questionId = (Long)attributes.get("questionId");

		if (questionId != null) {
			setQuestionId(questionId);
		}

		Long createUserId = (Long)attributes.get("createUserId");

		if (createUserId != null) {
			setCreateUserId(createUserId);
		}

		Long modifyUserId = (Long)attributes.get("modifyUserId");

		if (modifyUserId != null) {
			setModifyUserId(modifyUserId);
		}

		String decription = (String)attributes.get("decription");

		if (decription != null) {
			setDecription(decription);
		}

		Integer answerType = (Integer)attributes.get("answerType");

		if (answerType != null) {
			setAnswerType(answerType);
		}

		String correct = (String)attributes.get("correct");

		if (correct != null) {
			setCorrect(correct);
		}

		Integer answerPosition = (Integer)attributes.get("answerPosition");

		if (answerPosition != null) {
			setAnswerPosition(answerPosition);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifydate = (Date)attributes.get("modifydate");

		if (modifydate != null) {
			setModifydate(modifydate);
		}
	}

	public long getAnswerId() {
		return _answerId;
	}

	public void setAnswerId(long answerId) {
		_answerId = answerId;
	}

	public long getQuestionId() {
		return _questionId;
	}

	public void setQuestionId(long questionId) {
		_questionId = questionId;
	}

	public long getCreateUserId() {
		return _createUserId;
	}

	public void setCreateUserId(long createUserId) {
		_createUserId = createUserId;
	}

	public String getCreateUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getCreateUserId(), "uuid",
			_createUserUuid);
	}

	public void setCreateUserUuid(String createUserUuid) {
		_createUserUuid = createUserUuid;
	}

	public long getModifyUserId() {
		return _modifyUserId;
	}

	public void setModifyUserId(long modifyUserId) {
		_modifyUserId = modifyUserId;
	}

	public String getModifyUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getModifyUserId(), "uuid",
			_modifyUserUuid);
	}

	public void setModifyUserUuid(String modifyUserUuid) {
		_modifyUserUuid = modifyUserUuid;
	}

	public String getDecription() {
		return _decription;
	}

	public void setDecription(String decription) {
		_decription = decription;
	}

	public int getAnswerType() {
		return _answerType;
	}

	public void setAnswerType(int answerType) {
		_answerType = answerType;
	}

	public String getCorrect() {
		return _correct;
	}

	public void setCorrect(String correct) {
		_correct = correct;
	}

	public int getAnswerPosition() {
		return _answerPosition;
	}

	public void setAnswerPosition(int answerPosition) {
		_answerPosition = answerPosition;
	}

	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	public Date getModifydate() {
		return _modifydate;
	}

	public void setModifydate(Date modifydate) {
		_modifydate = modifydate;
	}

	public BaseModel<?> getAnswerRemoteModel() {
		return _answerRemoteModel;
	}

	public void setAnswerRemoteModel(BaseModel<?> answerRemoteModel) {
		_answerRemoteModel = answerRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			AnswerLocalServiceUtil.addAnswer(this);
		}
		else {
			AnswerLocalServiceUtil.updateAnswer(this);
		}
	}

	@Override
	public Answer toEscapedModel() {
		return (Answer)Proxy.newProxyInstance(Answer.class.getClassLoader(),
			new Class[] { Answer.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		AnswerClp clone = new AnswerClp();

		clone.setAnswerId(getAnswerId());
		clone.setQuestionId(getQuestionId());
		clone.setCreateUserId(getCreateUserId());
		clone.setModifyUserId(getModifyUserId());
		clone.setDecription(getDecription());
		clone.setAnswerType(getAnswerType());
		clone.setCorrect(getCorrect());
		clone.setAnswerPosition(getAnswerPosition());
		clone.setCreateDate(getCreateDate());
		clone.setModifydate(getModifydate());

		return clone;
	}

	public int compareTo(Answer answer) {
		long primaryKey = answer.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		AnswerClp answer = null;

		try {
			answer = (AnswerClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = answer.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{answerId=");
		sb.append(getAnswerId());
		sb.append(", questionId=");
		sb.append(getQuestionId());
		sb.append(", createUserId=");
		sb.append(getCreateUserId());
		sb.append(", modifyUserId=");
		sb.append(getModifyUserId());
		sb.append(", decription=");
		sb.append(getDecription());
		sb.append(", answerType=");
		sb.append(getAnswerType());
		sb.append(", correct=");
		sb.append(getCorrect());
		sb.append(", answerPosition=");
		sb.append(getAnswerPosition());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifydate=");
		sb.append(getModifydate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("com.swt.mto.thithu.model.Answer");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>answerId</column-name><column-value><![CDATA[");
		sb.append(getAnswerId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>questionId</column-name><column-value><![CDATA[");
		sb.append(getQuestionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createUserId</column-name><column-value><![CDATA[");
		sb.append(getCreateUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifyUserId</column-name><column-value><![CDATA[");
		sb.append(getModifyUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>decription</column-name><column-value><![CDATA[");
		sb.append(getDecription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>answerType</column-name><column-value><![CDATA[");
		sb.append(getAnswerType());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>correct</column-name><column-value><![CDATA[");
		sb.append(getCorrect());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>answerPosition</column-name><column-value><![CDATA[");
		sb.append(getAnswerPosition());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifydate</column-name><column-value><![CDATA[");
		sb.append(getModifydate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _answerId;
	private long _questionId;
	private long _createUserId;
	private String _createUserUuid;
	private long _modifyUserId;
	private String _modifyUserUuid;
	private String _decription;
	private int _answerType;
	private String _correct;
	private int _answerPosition;
	private Date _createDate;
	private Date _modifydate;
	private BaseModel<?> _answerRemoteModel;
}